package biz.datalk.industrialland.admin.config.properties;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author tarofang@163.com
 * @date 2024-01-26
 */
@Getter
@Setter
@ToString
@ConfigurationProperties(RedisDelayTaskExecutorProperties.PREFIX)
public class RedisDelayTaskExecutorProperties extends ExecutorProperties implements InitializingBean {
    public static final String PREFIX = "executor.redis-delay-task";

    private Boolean enable = true;

    /** 同一时刻，最大线程执行数 */
    private int semaphoreNum = 4;

    @Override
    public void afterPropertiesSet() throws Exception {
        if (StringUtils.equals(this.getThreadNamePrefix(), DEFAULT_THREAD_NAME_PREFIX)) {
            this.setThreadNamePrefix("REDIS-DELAY-TASK-");
        }
        if (this.getTransferRequestAttributes() == null) {
            this.setTransferRequestAttributes(Boolean.FALSE);
        }
    }
}
